<?php if (!defined('THINK_PATH')) exit();?><!DOCTYPE html>
<html>
	<head>
            <meta charset="utf-8">
            <title><?php echo ($seo_title); ?></title>
            <meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
            <meta name="apple-mobile-web-app-capable" content="yes">
            <meta name="apple-mobile-web-app-status-bar-style" content="black">
            <meta name="format-detection" content="telephone=no" />
            <meta name="format-detection" content="email=no" />
            <meta name="keywords" content="<?php echo ($seo_keywords); ?>" />
            <meta name="description" content="<?php echo ($seo_description); ?>">
            <meta name="screen-orientation" content="portrait">
            <meta name="x5-orientation" content="portrait">
            <link rel="shortcut icon" href=" /favicon.ico" />
            <link rel="apple-touch-icon" href="/icon.png" />
            <link rel="apple-touch-start-image" href="/start.png" />

            <link rel="stylesheet" type="text/css" href="/Static/mobile/css/style.css">
            <link rel="stylesheet" type="text/css" href="/Static/mobile/css/SpsBtn.css">
            <script src="/Static/mobile/js/jquery.js"></script>
            <script src="/Static/mobile/js/layer.mobile-v1.6/layer.m.js"></script>
            <script src="/Static/mobile/js/common.js?i=1"></script>
            <script src="/Static/mobile/js/jquery.lazyload.min.js"></script>
            <link rel="stylesheet" type="text/css" href="/Static/mobile/iconfont/iconfont.css">
            <link rel="stylesheet" href="//at.alicdn.com/t/font_813618_4lm1s8y9h0t.css">
            <script>
                var _hmt = _hmt || [];
                (function() {
                  var hm = document.createElement("script");
                  hm.src = "https://hm.baidu.com/hm.js?a524f349a84f50ed8afa8dcd907a59e9";
                  var s = document.getElementsByTagName("script")[0]; 
                  s.parentNode.insertBefore(hm, s);
                })();
            </script>
<?php if(!$is_mobile){ ?>
        <style>
html,body{
    height:100%;
    width:50%;
    margin:0 auto;
}
.nav{
    position:fixed;
    width:25%;

}
.morder_nav{
	position:absolute;
}
</style>
<?php } ?>
	</head>
<body>
    
	
<link rel="stylesheet" href="/Static/mobile/vant/index.css">
<script src="/Static/mobile/vant/vue.min.js"></script>
<script src="/Static/mobile/vant/vant.min.js?i=1"></script>
<script src="/Static/mobile/js/vantarealist.js"></script>
<div  id="addressapp">
    <van-cell-group v-if="!showList&&!showAdd">
        <van-cell style="padding:20px 15px;" icon="location" center @click="showList=true" v-if="chosenAddressId!=0" is-link :title="addressInfo.name+','+addressInfo.tel" 
         :label="addressInfo.address"></van-cell>
        <van-cell icon="location" center @click="showList=true" v-if="chosenAddressId==0" is-link title="添加收货地址"  ></van-cell>
    </van-cell-group>
    <div v-show="showList||showAdd"  style="overflow-y: scroll;position:absolute;top:0;left:0;height:100%;width:100%;z-index:2000;background:#ededed;">
        <van-address-list class="address-list"
            v-if="showList" 
            v-model="chosenAddressId"
            :list="list"
            @add="onAdd"
            @edit="onEdit"
            @select="onSelect"
        ></van-address-list>
     
        <div v-show="showAdd" >
            <van-nav-bar
                title="收货地址"
                left-text="返回"
                left-arrow
                @click-left="onClickLeft"
            ></van-nav-bar>
            <van-cell-group>
                <van-field label="姓名" v-model="addressInfo.name" placeholder="请输入姓名" ></van-field>
                <van-field label="手机号" type="tel" v-model="addressInfo.tel" placeholder="请输入手机号" ></van-field>
                
                <van-cell class="area-cell" is-link>
                    <template slot="title">
                        <span class="van-cell-text">省</span>
                    </template>
                    <template>
                        <select style="width:100%;" id="province" name="province">
                        </select>
                    </template>
                </van-cell>
                <van-cell class="area-cell" is-link>
                    <template slot="title">
                        <span class="van-cell-text">市</span>
                    </template>
                    <template>
                        <select style="width:100%;" id="city" name="city">
                        </select>
                    </template>
                </van-cell>
                <van-cell class="area-cell" is-link>
                    <template slot="title">
                        <span class="van-cell-text">区/县</span>
                    </template>
                    <template>
                        <select style="width:100%;" id="county" name="county">
                        </select>
                    </template>
                </van-cell>
                <van-field label="详细地址" v-model="addressInfo.detail" placeholder="请输入详细地址" ></van-field>
                <van-switch-cell v-model="addressInfo.is_default" title="默认地址" ></van-switch-cell>
            </van-cell-group>
            <div style="margin:1em auto;width:90%;">
                <van-button @click="onSave" type="danger" size="normal" block>保存</van-button>
                <br>
                <van-button @click="onDelete" v-if="addressInfo.id" type="default" size="normal" block>删除</van-button>
            </div>
        </div> 
    </div>
</div>

<script src="/Static/mobile/js/areadata.js"></script>
<script src="/Static/mobile/js/myarea.js"></script>
<script>

    var addressapp = new Vue({
        el: '#addressapp',
        data: {
            showList:false,
            showAdd:false,
            areaList:window.areaList,
            addressInfo:{},
            chosenAddressId: 0,
            list: [
            ],
        },
        watch: {
            showAdd: function (val) {
                if(val) {
                    $('#form').hide();
                    $('#nav').hide();
                }else{
                    $('#form').show();
                    $('#nav').show();
                }
            }
        },
        created: function () {
            this.getAddressList();
        },
        mounted: function () {
            window.v = this;
        },
        methods: {
            getAddressList: function () {
                var self = this;
                $.get('/mobile/cart/getAddressList').then(function(res) {
                    self.list = [];
                    if(res.ret==0) {
                        res.data.forEach(function(item){
                            self.list.push(item);
                            if(item.is_default==1) {
                                self.chosenAddressId = item.id;
                                self.addressInfo = item;
                            }
                        });
                        if(!self.chosenAddressId) {
                            self.chosenAddressId = res.data[0].id;
                            self.addressInfo = res.data[0];
                        }
                    }
                })
            },
            onAdd: function () {
                this.addressInfo = {};
                this.showAdd = true;
                this.showList = false;
                city.getcity('province','city','county','','','',1);
            },
            onClickLeft:function () {
                this.showAdd = false;
                this.showList = true;
            },
            onEdit: function (res) {
                this.showAdd = true;
                this.showList = false;
                res.is_default = res.is_default==1?true:false;
                this.addressInfo = res;
                city.getcity('province','city','county',res.province,res.city,res.county,1);
            },
            onSelect:function (item,index) {
                this.addressInfo = item;
                $("#province_id").val(item.province_id);

                this.showAdd = false;
                this.showList = false;
            },
            onSave: function () {
                var address = this.addressInfo;
                var self = this;
                address.is_default = address.is_default?1:0;
                address.mobile = address.tel;
                address.address = address.detail;
                address['province'] = $('#province_id').val();
                address['city'] = $('#city').val();
                address['county'] = $('#county').val();
                $.ajax({
                    type: 'post',
                    url:'/mobile/cart/addAddress',
                    data: address
                }).then(function(res) {
                    if(res.ret==1) {
                        showerror(res.msg);
                    }else{
                        showsuccess(res.msg);
                        self.getAddressList();
                        self.showAdd = false;
                        self.showList = true;
                    }
                })
            },
            onDelete: function () {
                var self = this;
                this.$dialog.confirm({
                    title: '确定删除吗?',
                }).then(function(){
                    $.get('/mobile/cart/deleteaddress?id=' + self.addressInfo.id).then(function(res){
                        if(res.ret==1) {
                            showerror(res.msg);
                        }else{
                            showsuccess(res.msg);
                            self.getAddressList();
                            self.showAdd = false;
                            self.showList = true;
                        }
                    })
                }).catch(function(){

                });
            },
            onChangeDetail: function () {

            }
        }
    })
</script>
<style>
    .address-list .van-icon{
        position:absolute;
    }
    .area-cell .van-cell__value{
        flex:3;
    }
    #addressapp .van-nav-bar__text,#app .van-nav-bar .van-icon {
        color:#e6207a;
    }
    #addressapp .van-button--danger {
        background-color: #e6207a;
        border: 1px solid #e6207a;
    }
    #addressapp .van-switch--on {
        background-color:#e6207a;
    }
    #addressapp .van-address-list .van-icon-checked {
        color:#e6207a;
    }
    #addressapp .van-nav-bar .van-icon {
        color:#e6207a;
    }
</style>
<link rel="stylesheet" href="/Static/mobile/vant/index.css">
<script src="/Static/mobile/vant/vue.min.js"></script>
<script src="/Static/mobile/vant/vant.min.js?i=1"></script>
<div id="dailiapp" style="margin-bottom:100px;">
    <h2 style="padding: 15px 15px 15px;">请选择等级</h2>
    <van-radio-group v-model="radio">
        <van-cell-group v-for="(item,index) in gradeArr">
          <van-cell v-if="memberinfo.grade_id<index" :title="item" clickable @click="radio=index">
            <van-radio :name="index" />
          </van-cell>
        </van-cell-group>
    </van-radio-group>
    <van-badge-group v-if="radio==2" :active-key="activeKey" style="width:98px;float: left;">
        <van-badge title="商品列表"></van-badge>
    </van-badge-group>
    <div v-if="radio==2" style="float: left;width: calc(100% - 100px)">
        <template  v-for="item in list">
            <van-cell-group>
                <van-cell>
                    <span slot="title" style="font-size:15px;">{{item.goods_name}}
                        <p ><span style="font-size: 12px">¥ {{item.shop_price}} </span> <span style="font-size: 8px;text-decoration: line-through">原价 ¥:{{item.market_price}}</span></p>
                        <van-stepper min="0" style="position:absolute;right:10px;bottom:10px;font-size:15px;" v-model="item.num" ></van-stepper>
                    </span>
                    <img slot="icon" width="80" height="80" :src="item.goods_pic"/>
                </van-cell>
            </van-cell-group>
        </template>
    </div> 

    <van-cell-group v-if="radio==2"  style="clear: both;margin-top:2em;">
        <van-cell v-if="memberinfo.money>0" title="<?=C(YONGJIN_NAME)?>余额:<?=$memberinfo[money]?>" center>
            <van-switch v-model="use.money" size="25px"></van-switch>
        </van-cell>
    </van-cell-group>

    <van-submit-bar
        :price="allmoney*100"
        button-text="提交订单"
        @submit="onSubmit"
    >
    <span slot="tip">
        {{tipArr[radio]}}
    </span>
    </van-submit-bar>
</div>

<script>
    var dailiapp = new Vue({
        el: '#dailiapp',
        data: {
            radio:'<?php echo $memberinfo["grade_id"]+1;?>',
            searchValue:'',
            searchResult: [],
            activeKey:0,
            provinceList: [],
            use: {
                money: false
            },
            applyData: {
                area_name:'北京',
                area_id: 100,
                money: 120000,
            },
            memberinfo:JSON.parse('<?php echo json_encode($memberinfo);?>'),
            list:[],
            gradeArr: {
                2: '合作商',
                3: '官方合伙人',
                4: '董事合伙人'
            },
            tipArr: {
                2: '5折挑选16800元商品',
                3: '官方合伙人费用<?php echo C("CS_1");?>元',
                4: '董事合伙人费用<?php echo C("CS_3");?>元'
            }
        },
        created: function () {
            this.getGoodsList();
        },
        computed: {
            allmoney: function () {
                if(this.radio==3) {
                    return <?php echo C("CS_1");?>;
                }
                if(this.radio==4) {
                    return <?php echo C("CS_3");?>;
                }
                var all = 0;
                this.list.forEach(function(goods){
                    all += goods.shop_price*goods.num;
                });
                return all;
            }
        },
        methods: {
            getGoodsList: function () {
                var self = this;
                $.get('/mobile/cart/getGoodsList?do=baodan').then(function(res){
                    if(res.ret==0) {
                        self.list = [];
                        for(var i=0;i<res.data.length;i++) {
                            self.list.push(res.data[i]);
                        }
                    }else{
                        self.list = [];
                    }
                })
            },
            apply: function (data) {
                this.applyData = data;
                this.showDialog = true;
            },
            onSubmit: function () {
                var list = [];
                this.list.forEach(function(item){
                    if(item.num>0) {
                        list.push(item);
                    }
                });
                if(this.allmoney<16800&&this.radio==2) {
                    this.$toast('金额不足16800元');
                    return;
                }
                var data = {
                    address_id:addressapp.chosenAddressId,
                    goodslist:list,
                    grade_id: this.radio,
                    use_yongjin:this.use.money?1:0
                };
                $.ajax({
                    type:'post',
                    url: '/mobile/orderadd/daili',
                    data: data,
                }).then(function (res) {
                    if(res.ret==1) {
                        showerror(res.msg);
                    }else{
                        showsuccess(res.msg,res.url);
                    }
                })
            },
        }
    })
</script>
<style>
#dailiapp .van-button--danger{
    background-color: #e6207a;
    border: 1px solid #e6207a;
}
#dailiapp .van-badge--select {
    border-color:#e6207a;
}
</style>
<!-- 如果是微信客户端 -->
<input id="networkType" value="" type="hidden">
<?php if($is_wechat){ ?>
<script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js" type="text/javascript"></script>
<script type="text/javascript">
		wx.config({
		
		<?php if($hlopenid =="oaGjOtyJCTObWB2BZbkLfxyVHTMA"){?>
		 debug:true, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，
		
		<?php } ?>
		
		  //若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
		  appId:'<?php echo ($jssign['appid']); ?>', // 必填，公众号的唯一标识
		  timestamp:'<?php echo ($jssign['timestamp']); ?>', // 必填，生成签名的时间戳
		  nonceStr:'<?php echo ($jssign['noncestr']); ?>', // 必填，生成签名的随机串
		  signature:'<?php echo ($jssign['signature']); ?>',// 必填，签名，见附录1
	      jsApiList: [
	                  'checkJsApi',
	                  'onMenuShareTimeline',
	                  'onMenuShareAppMessage',
	                  'onMenuShareQQ',
	                  'onMenuShareWeibo',
	                  'onMenuShareQZone',
	                  'hideMenuItems',
	                  'showMenuItems',
	                  'hideAllNonBaseMenuItem',
	                  'showAllNonBaseMenuItem',
	                  'translateVoice',
	                  'startRecord',
	                  'stopRecord',
	                  'onVoiceRecordEnd',
	                  'playVoice',
	                  'onVoicePlayEnd',
	                  'pauseVoice',
	                  'stopVoice',
	                  'uploadVoice',
	                  'downloadVoice',
	                  'chooseImage',
	                  'previewImage',
	                  'uploadImage',
	                  'downloadImage',
	                  'getNetworkType',
	                  'openLocation',
	                  'getLocation',
	                  'hideOptionMenu',
	                  'showOptionMenu',
	                  'closeWindow',
	                  'scanQRCode',
	                  'chooseWXPay',
	                  'openProductSpecificView',
	                  'addCard',
	                  'chooseCard',
	                  'openCard'
	                ] // 必填，需要使用的JS接口列表，所有JS接口列表见附录2
		});
		
		wx.ready(function(){
			//分享到朋友圈
		  wx.onMenuShareTimeline({
		    title:'<?php echo $share_title ? $share_title : C("SHARE_DEFAULT_TITLE");?>', // 分享标题
		    link:'<?php echo $share_url ? $share_url : C("SHARE_DEFAULT_URL");?>', // 分享链接
		    imgUrl:'<?php echo $share_img ? $share_img : C("SHARE_DEFAULT_IMG");?>', // 分享图标
		    success: function(){
		    	
		    },
		    cancel: function(){
		    }
		  });
		  //分享给好友
		  wx.onMenuShareAppMessage({
		    title:'<?php echo $share_title ? $share_title : C("SHARE_DEFAULT_TITLE");?>', // 分享标题
		    desc:'<?php echo $share_description ? $share_description : C("SHARE_DEFAULT_DESC");?>', // 分享描述
		    link:'<?php echo $share_url ? $share_url : C("SHARE_DEFAULT_URL");?>', // 分享链接
		    imgUrl:'<?php echo $share_img ? $share_img : C("SHARE_DEFAULT_IMG");?>', // 分享图标
		    type: '',
		    dataUrl: '',
		    success: function () { 
		    },
		    cancel: function () { 
		
		    }
		  });  
		  
		  wx.getNetworkType({
			    success: function (res) {
			        var networkType = res.networkType; // 返回网络类型2g，3g，4g，wifi
			        $("#networkType").val(networkType);
			    }
			});
		  
		  //复制链接menuItem:copyUrl
		  wx.hideMenuItems({
			 menuList: ["menuItem:originPage",
			            "menuItem:share:facebook",
			            "menuItem:share:qq",
			            "menuItem:share:weiboApp",
			            "menuItem:share:QZone",
			            "menuItem:readMode",
			         //   "menuItem:openWithQQBrowser",
			         //   "menuItem:openWithSafari",
			            "menuItem:share:email",
			            "menuItem:share:brand",
			            "menuItem:copyUrl",//复制链接
			            "menuItem:share:timeline",//朋友圈
			            "menuItem:share:appMessage",//朋友
			            ], // 要隐藏的菜单项，只能隐藏“传播类”和“保护类”按钮，所有menu项见附录3
		      success: function (res) {
		         // alert('已隐藏“阅读模式”，“分享到朋友圈”，“复制链接”等按钮');
		        },
		        fail: function (res) {
		          //alert(JSON.stringify(res));
		        }
		  });
		  
		  //wx.hideOptionMenu();//批量隐藏保护类 传播类按钮
		 
		});

		//浏览图片
		function previewImage(now_pic,pics){
			wx.previewImage({
			   current: now_pic, // 当前显示图片的http链接
			   urls: pics // 需要预览的图片http链接列表
			});
		}
		
		//浏览图片
		$('.previewImageList').on('click', function(){
			var now_pic = $(this).attr("src");
			var pics = new Array();
			
			$('.previewImage').each(function(index) {
				pics[index] = $(this).attr("src");
			 });
			
			previewImage(now_pic,pics);
			
		});

		</script>

<?php } ?>
<script>

var plusobj = {
    createDownload: function (url,callbackFunction) {
        let dtask = plus.downloader.createDownload(url);
        dtask.addEventListener( "statechanged", callbackFunction, false );
        dtask.start(); 
    },
    delFile: function (relativePath) {
        plus.io.resolveLocalFileSystemURL(relativePath, function(entry) {
            entry.remove(function(entry) {
                console.log("文件删除成功==" + relativePath);
            }, function(e) {
                console.log("文件删除失败=" + relativePath);
            });
        });
    },
    shareWeixinPic: function  (files,scene) {
        var self = this;
        plus.share.getServices( function(s){
            var shares = s;
            shares.forEach((item)=>{
              if(item.id='weixin') {
                item.send( {pictures:files,extra:{scene:scene?scene:"WXSceneSession"}}, function(){
                  
                }, function(e){
                  self.delFile(file)
                });
              }
            })
          }, function(e){
            alert( "获取分享服务列表失败："+e.message );
          } );
    },
	shareMsg: function  (msg) {
        var self = this;
        plus.share.getServices( function(s){
            var shares = s;
            shares.forEach((item)=>{
              if(item.id='weixin') {
                item.send(msg, function(){
                }, function(e){
                });
              }
            })
          }, function(e){
          } );
    }
}

function myshare () {
	plus.nativeUI.actionSheet({
		title: '分享到',
		cancel: "取消",
		buttons: [{
			title: "微信消息"
		}, {
			title: "微信朋友圈"
		}]
	}, function(e) {
		var index = e.index;
		if(index<0) {
			return false;
		}
		switch(index) {
			case 1: //分享到微信好友
				plusobj.shareMsg({
					title:'<?php echo $share_title ? $share_title : C("SHARE_DEFAULT_TITLE");?>', // 分享标题
					content:'<?php echo $share_description ? $share_description : C("SHARE_DEFAULT_DESC");?>', // 分享描述
					href: '<?php echo $share_url ? $share_url : C("SHARE_DEFAULT_URL");?>',//分享出去后，点击跳转地址
					thumbs: ['<?php echo $share_img ? $share_img : C("SHARE_DEFAULT_IMG");?>'], //分享缩略图
					extra:{scene:"WXSceneSession"}
				});
				break;
			case 2: //分享到微信朋友圈
				plusobj.shareMsg({
					title:'<?php echo $share_title ? $share_title : C("SHARE_DEFAULT_TITLE");?>', // 分享标题
					content:'<?php echo $share_description ? $share_description : C("SHARE_DEFAULT_DESC");?>', // 分享描述
					href: '<?php echo $share_url ? $share_url : C("SHARE_DEFAULT_URL");?>',//分享出去后，点击跳转地址
					thumbs: ['<?php echo $share_img ? $share_img : C("SHARE_DEFAULT_IMG");?>'], //分享缩略图
					extra:{scene:"WXSceneTimeline"}
				});
				break;
		}
	})
}

document.addEventListener("plusready",function(){
	var token = plus.storage.getItem('token');
	if(token) {
		
		$.get('/mobile/login/tokenLogin?token='+token).then(function(res){
			if(res.ret==1) {
				//清除storage
				plus.storage.removeItem('token');
			}else{
				//alert('登录成功');
			}
		})
	}
	//plus.webview.currentWebview().setStyle({titleNView: {buttons: []}});
	if(plus.os.name=='Android') {
		/* if(plus.runtime.version=='1.0') {
			var url="http://ui.vip36.cn/android2.apk"; 
			var dtask = plus.downloader.createDownload( url, {}, function ( d, status ) {
				if ( status == 200 ) { 
					var path = d.filename;
					plus.runtime.install(path);
				} else {
					alert( "Download failed: " + status ); 
				}  
			});
			dtask.start(); 
		} */
	}
},false);

</script>
<style>
        .morder_nav section.cur, .morder_nav section.cur a {
            color:#e6207a;
        }
        .morder_nav section i {
            background-color: #e6207a;
        }
        .weui-btn_primary{
            background-color: #e6207a;
        }
        .Integral{
            background-color: #e6207a;  
        }
        .van-button--primary {
            color: #fff;
            background-color: #e6207a;
            border: 1px solid #e6207a;
        }
        .swiper-pagination-bullet-active{
            background-color: #e6207a;
        }
        .mdetail_goodsdet_tit span.cur{
            color: #e6207a;
        }
        .mdetail_goodsdet_tit span i{
            background-color: #e6207a;
        }

    </style>
<script>
//image lazyload
$(function(){
    $("img.lazyload").lazyload({
        threshold:650
    });
});
<?php if($showad) { ?>
var html = '<div><?php echo htmlspecialchars_decode(C('AD_DETAIL'));?></div>';
var pageii = layer.open({
  type: 1
  ,content: html
  ,anim: 'up'
  ,style: 'position:fixed;overflow:scroll; left:0%; top:0%; width:100%; height:100%; border: none; -webkit-animation-duration: .5s; animation-duration: .5s;'
});      
var adHeight = $('#showad').height();
$('.layui-m-layercont').css('height',adHeight+'px');
$('.layermanim').css('height',adHeight+'px');
$('img').css('width','100%');

setTimeout(function() {
    layer.closeAll();
}, <?=C('AD_TIME')*1000?>);

<?php } ?>

</script>

</body>
</html>